import { exec } from "child_process";
import path from "path";
import { app } from "electron";
import { fileURLToPath } from "node:url";

export const getSoftwarePath = () => {
  // 获取应用程序的根目录路径
  const appPath = app.getAppPath();
  console.log(appPath, "appPathappPath");
  // const __dirname = path.dirname(fileURLToPath(import.meta.url));

  // const pathToHtml = path.join(__dirname, "../dist/public/geek.exe");

  return {
    // geek: pathToHtml,
    geek: path.join(appPath, "electron", "software", "geek.exe"),
  };
};

export function startExternalSoftware(
  name: keyof ReturnType<typeof getSoftwarePath>,
) {
  const softwarePaths = getSoftwarePath();

  // 方法1：直接启动程序
  exec(`"${softwarePaths[name]}"`, (error, stdout, stderr) => {
    if (error) {
      console.error("启动失败:", error.message);
      return;
    }
    console.log("Geek Uninstaller 已启动");
  });
}
